package com.ruike.alisurface.project_DaTi;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ruike.alisurface.R;
import com.ruike.alisurface.Serials.MsgEventBus;
import com.ruike.alisurface.base.BaseAty;
import com.ruike.alisurface.project_DaTi.adapter.QuestionErrorInfoAdapter;
import com.ruike.alisurface.project_DaTi.bean.ResultAnswerBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: voodoo
 * CreateDate: 2020/07/23 023 09:40 上午
 * Description: 错题详情展示界面
 */
public class AnswerErrorInfoActivity extends BaseAty {

    @BindView(R.id.answerErrorInfo_show_recv)
    RecyclerView showRecv;

    private ResultAnswerBean resultAnswerBean;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_answer_error_info;
    }

    @Override
    protected void initViews() {
        initTitleBar(false);
        startCountdownTimer(120, null, null);
    }

    @Override
    protected void initData() {
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            resultAnswerBean = (ResultAnswerBean) bundle.getSerializable("resultAnswer");
        }

        // 移除答对的题目，只展示答错的题目
        List<ResultAnswerBean.DetailsBean> details = resultAnswerBean.getDetails();
        List<ResultAnswerBean.DetailsBean> tempDetailsBeans = new ArrayList<>();
        for (ResultAnswerBean.DetailsBean detailsBean : details) {
            if (detailsBean.isIs_right()) {
                tempDetailsBeans.add(detailsBean);
            }
        }
        if (tempDetailsBeans.size() > 0) {
            for (ResultAnswerBean.DetailsBean detailsBean : tempDetailsBeans) {
                details.remove(detailsBean);
            }
            tempDetailsBeans.clear();
        }

        QuestionErrorInfoAdapter adapter = new QuestionErrorInfoAdapter(this, details);
        showRecv.setLayoutManager(new LinearLayoutManager(this));
        showRecv.setAdapter(adapter);

    }

    @Override
    public void doEventBusResult(MsgEventBus event) {

    }

    @OnClick(R.id.answerErrorInfo_goback_imgv)
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.answerErrorInfo_goback_imgv:
                startCountdownTimer(0, null, null);
                break;
        }
    }

}
